package com.ruoyi.project.data.feedback.controller;

import java.sql.Timestamp;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.data.feedback.domain.DsImportFeedback;
import com.ruoyi.project.data.feedback.service.IDsImportFeedbackService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import java.util.Arrays;

import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 数据处理实时反馈Controller
 *
 * @author 魏刚
 * @date 2020-03-14
 */
@Controller
@RequestMapping("/data/feedback")
public class DsImportFeedbackController extends BaseController
{
    private String prefix = "data/feedback";

    @Autowired
    private IDsImportFeedbackService dsImportFeedbackService;

    @RequiresPermissions("data:feedback:view")
    @GetMapping()
    public String feedback()
    {
        return prefix + "/feedback";
    }
    /**
     * 查询数据处理实时反馈列表
     */
    @RequiresPermissions("data:feedback:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DsImportFeedback dsImportFeedback)
    {
        //startPage();
        List<DsImportFeedback> list = dsImportFeedbackService.list(new QueryWrapper<DsImportFeedback>(dsImportFeedback).orderByAsc("tr_date"));
        return getDataTable(list);
    }

    /**
     * 导出数据处理实时反馈列表
     */
    @RequiresPermissions("data:feedback:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DsImportFeedback dsImportFeedback)
    {
        List<DsImportFeedback> list = dsImportFeedbackService.list(new QueryWrapper<DsImportFeedback>(dsImportFeedback).orderByAsc("tr_date"));
        ExcelUtil<DsImportFeedback> util = new ExcelUtil<DsImportFeedback>(DsImportFeedback.class);
        return util.exportExcel(list, "feedback");
    }

    /**
     * 新增数据处理实时反馈
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存数据处理实时反馈
     */
    @RequiresPermissions("data:feedback:add")
    @Log(title = "数据处理实时反馈", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DsImportFeedback dsImportFeedback)
    {
        return toAjax(dsImportFeedbackService.saveOrUpdate(dsImportFeedback));
    }

    /**
     * 修改数据处理实时反馈
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        DsImportFeedback dsImportFeedback = dsImportFeedbackService.getById(id);
        mmap.put("dsImportFeedback", dsImportFeedback);
        return prefix + "/edit";
    }

    /**
     * 修改保存数据处理实时反馈
     */
    @RequiresPermissions("data:feedback:edit")
    @Log(title = "数据处理实时反馈", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DsImportFeedback dsImportFeedback)
    {
        return toAjax(dsImportFeedbackService.saveOrUpdate(dsImportFeedback));
    }

    /**
     * 删除数据处理实时反馈
     */
    @RequiresPermissions("data:feedback:remove")
    @Log(title = "数据处理实时反馈", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dsImportFeedbackService.removeByIds(Arrays.asList(ids.split(","))));
    }
    /**
     * 删除数据处理实时反馈
     */
    @RequiresPermissions("data:feedback:remove")
    @Log(title = "数据处理实时反馈", businessType = BusinessType.DELETE)
    @PostMapping( "/removeAll")
    @ResponseBody
    public AjaxResult removeAll()
    {
        return toAjax(dsImportFeedbackService.deleteAllDsImportFeedback());
    }
}
